﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Microsoft.Practices.Repository;
using DotNetCore.BannerManagement.Domain;

namespace DotNetCore.BannerManagement.DAL.Domain.dnc_ImageRepositoryArtifacts
{
    /// <summary>
    /// Construct a dnc_Image object from a datareader.
    /// </summary>
    internal class Getdnc_ImageByIDFactory : IDomainObjectFactory<dnc_Image>
    {
        public dnc_Image Construct(IDataReader reader)
        {
            dnc_Image dnc_Image = new dnc_Image();

            int contentTypeIndex = reader.GetOrdinal("ContentType");
            if (!reader.IsDBNull(contentTypeIndex))
            {
                dnc_Image.ContentType = reader.GetString(contentTypeIndex);

            }

            int heightIndex = reader.GetOrdinal("Height");
            if (!reader.IsDBNull(heightIndex))
            {
                dnc_Image.Height = reader.GetDecimal(heightIndex);

            }

            int iDIndex = reader.GetOrdinal("ID");
            if (!reader.IsDBNull(iDIndex))
            {
                dnc_Image.ID = reader.GetInt32(iDIndex);

            }

            int imageIndex = reader.GetOrdinal("Image");
            if (!reader.IsDBNull(imageIndex))
            {
                dnc_Image.Image = new Byte[(reader.GetBytes(imageIndex, 0, null, 0, int.MaxValue))];
                reader.GetBytes(imageIndex, 0, dnc_Image.Image, 0, dnc_Image.Image.Length);

            }

            int nameIndex = reader.GetOrdinal("Name");
            if (!reader.IsDBNull(nameIndex))
            {
                dnc_Image.Name = reader.GetString(nameIndex);

            }

            int widthIndex = reader.GetOrdinal("Width");
            if (!reader.IsDBNull(widthIndex))
            {
                dnc_Image.Width = reader.GetDecimal(widthIndex);

            }


            return dnc_Image;
        }
    }
}

